/**
 * Copyright 2006 gworks.com.au
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. (http://www.apache.org/licenses/LICENSE-2.0)
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed 
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for 
 * the specific language governing permissions and limitations under the License.
 *
 * <dhamma-message src="Atisha (11th century Tibetan Buddhist master)">
 * 	The greatest achievement is selflessness. The greatest worth is self-mastery.
 * 	The greatest quality is seeking to serve others. The greatest precept is continual awareness.
 * 	The greatest medicine is the emptiness of everything. The greatest action is not conforming with the worlds ways.
 * 	The greatest magic is transmuting the passions. The greatest generosity is non-attachment.
 * 	The greatest goodness is a peaceful mind. The greatest patience is humility.
 * 	The greatest effort is not concerned with results. The greatest meditation is a mind that lets go.
 * 	The greatest wisdom is seeing through appearances. 
 * </dhamma-message>
 */
package au.com.gworks.jump.app.wiki.server.mockimpl;

import java.security.Principal;
import java.util.Date;

import javax.servlet.FilterConfig;


import au.com.gworks.jump.app.util.RequestInterceptor;
import au.com.gworks.jump.app.util.RequestInterceptorPlugin;
import au.com.gworks.jump.io.ResourceAttributes;
import au.com.gworks.jump.io.ResourceNotFound;
import au.com.gworks.jump.io.UnauthorisedAccess;


/**
 * Rationale:
 * <p>
 * To provide pluggable repository preparation and closer behaviour wrapped 
 * around each request for the mock implementation.
 * </p>
 * Responsibilities:
 * <ul>
 * 	<li> initialise the file system provider and the thread local
 * 	<li> create a RequestPathInfo object
 * 	<li> close the repository after upon completion of the thread/request 
 * </ul>
 * Collaborators:
 * <ul>
 * 	<li> called by the RequestInterceptor
 * 	<li> FileSystemProvider
 * </ul>
 * Constraints:
 * <ul>
 * 	<li> only a single instance will be created and associated to the RequestInterceptor
 * 	<li> implementations must be thread safe and should consider avoiding instance
 * 		 variables
 * </ul>
 * 
 * @see RequestInterceptor
 * @see FileSystemProvider
 * @author Ashin Wimalajeewa (ash)
 */
public class FspInterceptorPlugin extends RequestInterceptorPlugin.AbstractBase {
	public void init(FilterConfig filterConfig) {
		// do nothing
	}
	
	public Integer getLatestRevision() {
		return FileSystemProvider.HEAD_REVISION;
	}

	public int getPathStatus(String path, Integer revision) {
		return FileSystemProvider.getInstance().getPathStatus(path);
	}

	public String getRepositoryNamespace() {
		return FileSystemProvider.getInstance().namespace;
	}

	public ResourceAttributes getResourceAttributes(String path, Integer revision) throws UnauthorisedAccess, ResourceNotFound {
		return FileSystemProvider.getInstance().getResourceAttributes(path);
	}

	public Integer getRevisionForDate(Date date) {
		return FileSystemProvider.HEAD_REVISION;
	}

	public boolean isAdministator() {
		return FileSystemProvider.getInstance().isAdministrator();
	}

	public void closeRepository() {
		FileSystemProvider.getInstance().close();
	}

	public void openRepository(String namespace, Principal requester) {
		FileSystemProvider fs = new FileSystemProvider(namespace, requester.getName());
		fs = null;
	}
}